﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using KPIS.GERP.GHRMS.BLL;
using KPIS.GERP.GHRMS.IBLL;
using Telerik.Web.UI;

namespace KPIS.GERP.GHRMS.APP.App_UI.Forms
{
    public partial class PR_SalaryDetail : System.Web.UI.Page
    {
        private SsMng ssMng = new SsMng();
        private ISalaryTypeBLL salaryTypeBLL = new SalaryTypeBLL();

        protected void Page_Load(object sender, EventArgs e)
        {
            Session["id"] = Request.QueryString["idSD"];
            lblID.Text = Request.QueryString["idET"];            

            if (!IsPostBack)
            {
                LoadDataGrid();
            }

        }

        private void LoadDataGrid()
        {
            try
            {
                DataSet salaryTypeList = salaryTypeBLL.ListSalaryType(Session["id"].ToString());
                lblCountItem.Text = salaryTypeList.Tables[0].Rows.Count.ToString();
                RadGrid2.DataSource = salaryTypeList.Tables[0];
                RadGrid2.DataBind();

            }
            catch (Exception ex)
            {

            }
        }

        protected void RadGrid2_ItemCommand(object source, Telerik.Web.UI.GridCommandEventArgs e)
        {
            if (e.CommandName == "Delete")
            {
                int seq = Convert.ToInt32((e.Item as GridDataItem).OwnerTableView.DataKeyValues[e.Item.ItemIndex]["grp_dtls_seq"]);
                salaryTypeBLL.Delete(seq, ssMng.EmpSeq);
            }

            LoadDataGrid();

        }

        protected void RadGrid2_ItemCreated(object sender, GridItemEventArgs e)
        {
            if (e.Item is GridCommandItem)
            {
                GridCommandItem commandItem = e.Item as GridCommandItem;
                LinkButton button = commandItem.FindControl("cmdAddNew") as LinkButton;

                if (lblID.Text == "1" && int.Parse(lblCountItem.Text) > 0)
                {
                    button.Enabled = false;
                    button.Visible = true;
                    button.Text = "";
                }
            }
        }

        protected void RadGrid2_ItemDataBound(object sender, GridItemEventArgs e)
        {
            try
            {

            }
            catch
            { }
        }
    }
}
